const { Application } = require('ee-core');
const { exec, spawn } = require('child_process');
const { app: electronApp } = require("electron");

class Index extends Application {

  constructor() {
    super();
    // this === eeApp;
  }

  /**
   * core app have been loaded
   */
  async ready () {
    // do some things
    // 解决跨域
    electronApp.commandLine.appendSwitch("disable-web-security");
  }

  /**
   * electron app ready
   */
  async electronAppReady () {
    // do some things
  }

  /**
   * main window have been loaded
   */
  async windowReady () {
    // do some things
    // 执行数字人bat脚本
    // console.log("执行bat脚本-------")
    // exec('start D:\\dh-runtime/socket-server.bat',{
    //   windowsHide: true,
    //   shell: false,
    // }, (error, stdout, stderr) => {
    //   if (error) {
    //     console.error(`执行的错误: ${error}`);
    //     return;
    //   }
    //   console.log(`stdout: ${stdout}`);
    //   console.error(`stderr: ${stderr}`);
    // });

    // 延迟加载，无白屏
    const winOpt = this.config.windowsOption;
    if (winOpt.show == false) {
      const win = this.electron.mainWindow;
      win.once('ready-to-show', () => {
        win.show();
        win.focus();
      })
    }
  }

  /**
   * before app close
   */  
  async beforeClose () {
    // do some things
    console.log('before close----')
  }
}

Index.toString = () => '[class Index]';
module.exports = Index;